<?php
declare(strict_types=1);

namespace app\admin\controller;

use app\common\controller\AdminController;
use app\common\utils\JsonResponse;
use think\App;
use app\common\model\Menu;

class Router extends AdminController
{
    protected $menuModel;
    
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->menuModel = new Menu();
    }
    
    /**
     * 获取路由列表
     */
    public function getList()
    {
        try {
            // 直接传入角色列表获取路由
            $menus = $this->menuModel->getRouters($this->adminInfo['roles'] ?? []);
            return JsonResponse::success([
                'list' => $menus,
                'home_path' => '/dashboard'  // 默认首页路径
            ]);
        } catch (\Exception $e) {
            return JsonResponse::error($e->getMessage());
        }
    }
} 